package cn.interestingshop.web.manager;

import cn.interestingshop.entity.Notice;
import cn.interestingshop.service.notice.NoticeService;
import cn.interestingshop.service.notice.NoticeSserviceImpl;
import cn.interestingshop.utils.EmptyUtils;
import cn.interestingshop.utils.Pager;
import cn.interestingshop.web.AbstractServlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


@WebServlet(name = "NoticeServlet",urlPatterns = "/manager/notice")
public class NoticeServlet extends AbstractServlet {
    @Override
    public Class getServletClass() {
        return NoticeServlet.class;
    }



    public String queryNoticeList(HttpServletRequest request, HttpServletResponse response){


        String currentPage = request.getParameter("currentPage");
        int currentPageNo = EmptyUtils.isEmpty(currentPage)?1:Integer.valueOf(currentPage);




        NoticeService noticeService=new NoticeSserviceImpl();



        int count = noticeService.selectAllCount();

        Pager pager = new Pager(count,8,currentPageNo);
        pager.setUrl("manager/notice?action=queryNoticeList");


        List<Notice> list = noticeService.selectAll(currentPageNo,8);

        request.setAttribute("pager",pager);

        request.setAttribute("noticeList",list);

        return "/manager/notice/noticeList";
    }

    public String noticeDetail(HttpServletRequest request, HttpServletResponse response){





        NoticeService noticeService=new NoticeSserviceImpl();




        Notice notice = noticeService.selectOne(Integer.parseInt(request.getParameter("id")));

        request.setAttribute("Notice",notice);

        return "/manager/notice/noticeDetail";
    }
}
